/*--------------------------------------------------------------------------
 *  Copyright 2011 Taro L. Saito
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *--------------------------------------------------------------------------*/
//--------------------------------------
// XerialJ
//
// SilkTuple.java
// Since: 2011/06/12 10:44:00
//
// $URL$
// $Author$
//--------------------------------------
package org.xerial.silk.model;

import java.util.ArrayList;
import java.util.List;

import org.xerial.util.StringUtil;
import org.xerial.util.UTF8String;

/**
 * Tuple of {@link SilkElement}s
 * 
 * @author leo
 * 
 */
public class SilkTuple implements SilkValue
{
    private static final List<SilkElement> EMPTY_TUPLE = new ArrayList<SilkElement>(0);
    private final List<SilkElement>        tuple;

    public SilkTuple() {
        this.tuple = EMPTY_TUPLE;
    }

    private SilkTuple(List<SilkElement> tuple) {
        this.tuple = new ArrayList<SilkElement>(tuple.size());
        for (SilkElement eachNode : tuple) {
            tuple.add(eachNode);
        }
    }

    public boolean isEmpty() {
        return tuple.isEmpty();
    }

    public int size() {
        return tuple.size();
    }

    @Override
    public boolean isSingle() {
        return false;
    }

    @Override
    public boolean isTuple() {
        return true;
    }

    @Override
    public UTF8String getValue() {
        return null;
    }

    @Override
    public String toString() {
        return String.format("(%s)", StringUtil.join(tuple, ", "));
    }

    public static class Builder
    {
        List<SilkElement> tuple = new ArrayList<SilkElement>();

        public Builder add(SilkElement v) {
            this.tuple.add(v);
            return this;
        }

        public SilkTuple build() {
            return new SilkTuple(tuple);
        }
    }

}
